using System;
using UnityEngine;

namespace QFramework
{
    public class MonoBehaviourBuilder : FluentBuilder
    {
        private Action mOnStart;
        private Action mOnUpdate;
        private Action mOnFixedUpdate;
        private Action mOnLateUpdate;
        private Action mOnDestroy;

        public MonoBehaviourBuilder(GameObject gameObject) : base(gameObject)
        {
        }

        public MonoBehaviourBuilder OnStart(Action onStart)
        {
            mOnStart = onStart;
            return this;
        }

        public MonoBehaviourBuilder OnUpdate(Action onUpdate)
        {
            mOnUpdate = onUpdate;
            return this;
        }

        public MonoBehaviourBuilder OnFixedUpdate(Action onFixedUpdate)
        {
            mOnFixedUpdate = onFixedUpdate;
            return this;
        }

        public MonoBehaviourBuilder OnLateUpdate(Action onLateUpdate)
        {
            mOnLateUpdate = onLateUpdate;
            return this;
        }

        public MonoBehaviourBuilder OnDestroy(Action onDestroy)
        {
            mOnDestroy = onDestroy;
            return this;
        }

        public void Build()
        {
            var monoBehaviour = mGameObject.AddComponent<FluentMonoBehaviour>();

            if (mOnStart != null) monoBehaviour.OnStartEvent += mOnStart;
            if (mOnUpdate != null) monoBehaviour.OnUpdateEvent += mOnUpdate;
            if (mOnFixedUpdate != null) monoBehaviour.OnFixedUpdateEvent += mOnFixedUpdate;
            if (mOnLateUpdate != null) monoBehaviour.OnLateUpdateEvent += mOnLateUpdate;
            if (mOnDestroy != null) monoBehaviour.OnDestroyEvent += mOnDestroy;
        }
    }
}